<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>16-字符串-翻转</title>
</head>
<body>
    <script>
    /* 
            第一种：
                字符串转数组，翻转数组，数组转字符串。
                
                split("")：根据空字符串拆分数组
                reverse()：数组反转元素位置
                join("")：数组转回字符串,且不带分隔符
    */
       let str = '01234';
       console.log(str);
       let arr = str.split('');
    //    console.log(arr);   //  ['0', '1', '2', '3', '4']
    
       arr = arr.reverse();
    //    console.log(arr);   //  ['4', '3', '2', '1', '0']
       str = arr.join('');
       console.log(str);  // 43210

       // 倒着遍历字符串 并定义新的空字符串
       let result = "这瓜保熟吗?";
       let newStr = '';
       for(let i = 0; i < result.length; i++){
           let temp = result[result.length - 1 -i];
           console.log(temp);
           newStr = newStr + temp;
       }
       console.log(newStr);
    </script>
</body>
</html>